﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace XnaSuperGame
{
	public class InputHandler : Microsoft.Xna.Framework.GameComponent
	{
	#region Class Fields
		
		static KeyboardState lastKeyBState;
		static KeyboardState keyBState;

		public KeyboardState KeyBState 
		{
			get {return keyBState;}
		}

		public KeyboardState LastKeyBState 
		{
			get { return lastKeyBState; }
		}

	#endregion

	#region Constructor

		public InputHandler(Game game) : base(game) 
		{
			keyBState = Keyboard.GetState();
		}

	
	#endregion

	#region Methods
		
		public override void Initialize()
		{
			base.Initialize();
		}

		public override void Update(GameTime gameTime)
		{
			lastKeyBState = keyBState;
			keyBState = Keyboard.GetState();
			base.Update(gameTime);
		}


		public bool KeyIsPressed(Keys key)
		{
			return keyBState.IsKeyDown(key) && lastKeyBState.IsKeyUp(key);
		}

		public bool KeyIsReleased(Keys key) 
		{
			return keyBState.IsKeyUp(key) && lastKeyBState.IsKeyDown(key);
		}

		public bool KeyIsDown(Keys key) 
		{
			return keyBState.IsKeyDown(key);
		}
		//<summary> 
		// Set  equality lastKeyBState = keyBState
		//</summary>
		public void Refresh ()
		{
			lastKeyBState = keyBState;
		}

	#endregion


	}


}
